home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / libtest / callbacks-example-displayheader.c < prev    next >
C/C++ Source or Header  |  2006-06-04  |  2KB  |  64 lines

  1. /*
  2.     HTTrack external callbacks example : display all incoming request headers
  3.     Example of <wrappername>_init and <wrappername>_exit call (httrack >> 3.31)
  4.     .c file
  5.  
  6.     How to build: (callback.so or callback.dll)
  7.       With GNU-GCC:
  8.         gcc -O -g3 -Wall -D_REENTRANT -shared -o mycallback.so callbacks-example.c -lhttrack1
  9.       With MS-Visual C++:
  10.         cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"mycallback.dll" callbacks-example.c libhttrack1.lib
  11.  
  12.       Note: the httrack library linker option is only necessary when using libhttrack's functions inside the callback
  13.  
  14.     How to use:
  15.       httrack --wrapper mycallback ..
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. /* Standard httrack module includes */
  23. #include "httrack-library.h"
  24. #include "htsopt.h"
  25. #include "htsdefines.h"
  26.  
  27. /* Local function definitions */
  28. static int process(t_hts_callbackarg *carg, httrackp *opt, 
  29.                    char* buff, const char* adr, const char* fil, 
  30.                    const char* referer_adr, const char* referer_fil, 
  31.                    htsblk* incoming);
  32.  
  33. /* 
  34. module entry point 
  35. */
  36. EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
  37.   const char *arg = strchr(argv, ',');
  38.   if (arg != NULL)
  39.     arg++;
  40.  
  41.   /* Plug callback functions */
  42.   CHAIN_FUNCTION(opt, receivehead, process, NULL);
  43.  
  44.   return 1;  /* success */
  45. }
  46.  
  47. static int process(t_hts_callbackarg *carg, httrackp *opt, 
  48.                    char* buff, const char* adr, const char* fil, 
  49.                    const char* referer_adr, const char* referer_fil, 
  50.                    htsblk* incoming) {
  51.  
  52.   /* Call parent functions if multiple callbacks are chained. */
  53.   if (CALLBACKARG_PREV_FUN(carg, receivehead) != NULL) {
  54.     if (!CALLBACKARG_PREV_FUN(carg, receivehead)(CALLBACKARG_PREV_CARG(carg), opt, buff, adr, fil, referer_adr, referer_fil, incoming)) {
  55.       return 0;  /* Abort */
  56.     }
  57.   }
  58.  
  59.   /* Process */
  60.   printf("[ %s%s ]\n%s\n", adr, fil, buff);
  61.  
  62.   return 1;   /* success */
  63. }
  64.